package acwing._1_1AlgorithmBasic;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing.Learning.AlgorithmTemplate
 * @File : _1_5TwoPointers.java
 * @Author : WangRuoyu
 * @Date 2023/3/11 10:29
 */

public class _1_5TwoPointers {
    // 双指针
    static int twoPointers(int[] q) { //求最长连续不重复子序列
        int[] a = new int[100010];
        int res = 0;
        for (int i = 0, j = 0; j < q.length; j++) {
            a[q[j]]++;
            while (a[q[j]] > 1) {
                a[q[i]]--;
                i++;
            }
            res = Math.max(res, j - i + 1);
        }
        return res;
    }
}

